//
//  SEDoctorAPI.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/21.
//

import Moya

enum SEDoctorAPI {
    /// 来源：0是图文问诊1预约挂号
    case doctorListOfOnlineInquiry(doctorName: String, hospitalId: String, departmentId: String, provinceId: String, cityId: String, areaId: String, page: Int)
    case doctorDetailInfo(id: String)
}

extension SEDoctorAPI: TargetType {
    var baseURL: URL { URL(string: SEApiManager.baseUrl)! }
    
    var path: String {
        switch self {
        case .doctorListOfOnlineInquiry: return "/smarteye/smarteye-base/doctor/diag/list"
        case .doctorDetailInfo: return "/smarteye/smarteye-base/doctor/query/all/detail"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .doctorListOfOnlineInquiry, .doctorDetailInfo:
            return .post
        }
    }
    
    var sampleData: Data { "".data(using: .utf8)! }
    
    var task: Task {
        SELog("\(path) - \(parameters)")
        switch self {
        case .doctorListOfOnlineInquiry,
             .doctorDetailInfo:
            return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
        }
    }
    
    var headers: [String : String]? { SEApiManager.headers }
    
    private var parameters: [String: Any] {
        switch self {
        case let .doctorListOfOnlineInquiry(doctorName, hospitalId, departmentId, provinceId, cityId, areaId, page):
            return ["doctorName": doctorName,
                    "hospitalId": hospitalId,
                    "deptId": departmentId,
                    "province": provinceId,
                    "city": cityId,
                    "region": areaId,
                    "pageNum": page,
                    "pageSize": 10]
        case let .doctorDetailInfo(id):
            return ["id": id]
        }
    }
}
